package com.j2eefast.bussiness.contract.service;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.j2eefast.bussiness.contract.entity.BusDepreciationEntity;
import com.j2eefast.bussiness.contract.entity.BusScrapEntity;
import com.j2eefast.bussiness.contract.mapper.BusDepreciationMapper;
import com.j2eefast.bussiness.contract.mapper.BusScrapMapper;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.framework.annotation.DataFilter;
import com.j2eefast.framework.sys.entity.SysUserEntity;
import com.j2eefast.framework.utils.Constant;
import com.j2eefast.framework.utils.UserUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * <p>报废管理</p>
 *
 * @author: summer
 * @date: 2021-05-31 14:41
 * @web: http://www.letukeji.cn
 * @version: 1.0.1
 */

@Service
public class BusScrapService extends ServiceImpl<BusScrapMapper, BusScrapEntity> {

    @Resource
    protected BusScrapMapper busScrapMapper;


    /**
     * 页面分页查询
     */
    public PageUtil findPage(Map<String, Object> params) {
        QueryWrapper<BusScrapEntity> r = new QueryWrapper<BusScrapEntity>();
        String useDepartment = (String) params.get("useDepartment");
        String equipmentName2 = (String) params.get("equipmentName2");
        String equipmentCode = (String) params.get("equipmentCode");
        String equipmentCode2 = (String) params.get("equipmentCode2");
        String equipmentName = (String) params.get("equipmentName");
        String equipmentModel = (String) params.get("equipmentModel");
        String beginTime=(String) params.get("beginTime");
        String endTime=(String) params.get("endTime");

        Page<BusScrapEntity> page = busScrapMapper.findPage(new Query<BusScrapEntity>(params).getPage(),
                StrUtil.nullToDefault(useDepartment,""),
                StrUtil.nullToDefault(equipmentCode,""),
                StrUtil.nullToDefault(equipmentName,""),
                StrUtil.nullToDefault(beginTime,""),
                StrUtil.nullToDefault(endTime,""),
                StrUtil.nullToDefault(equipmentName2,""),
                StrUtil.nullToDefault(equipmentCode2,""),
                StrUtil.nullToDefault(equipmentModel,"")
        );
        return new PageUtil(page);
    }

    public List<BusScrapEntity> findList(Map<String, Object> params) {
        QueryWrapper<BusScrapEntity> r = new QueryWrapper<BusScrapEntity>();
        String useDepartment = (String) params.get("useDepartment");
        String equipmentCode = (String) params.get("equipmentCode");
        String equipmentName = (String) params.get("equipmentName");
        String equipmentModel = (String) params.get("equipmentModel");
        String startTime=(String) params.get("startTime");
        String endTime=(String) params.get("endTime");
        List<BusScrapEntity> page = busScrapMapper.findList(new Query<BusScrapEntity>(params).getPage(),
                StrUtil.nullToDefault(useDepartment,""),
                StrUtil.nullToDefault(equipmentCode,""),
                StrUtil.nullToDefault(equipmentName,""),
                StrUtil.nullToDefault(startTime,""),
                StrUtil.nullToDefault(endTime,""),
                StrUtil.nullToDefault(equipmentModel,"")
        );
        return page;
    }


//    /**
//     * 页面展示查询翻页
//     */
//    public PageUtil findPage(Map<String, Object> params) {
//
//		//String parentId = (String) params.get("parentId");
//        Page<BusScrapEntity> page = busScrapMapper.findPage(
//                new Query<BusDepreciationEntity>(params).getPage(),
//				//StrUtil.nullToDefault(parentId,""),
//                (String) params.get(Constant.SQL_FILTER));
//        return new PageUtil(page);
//    }

    public boolean deleteByIds(Long[] ids) {

        return busScrapMapper.deleteByIds(ids);

    }

    public boolean updateCheck(Long id) {
        Long userId= UserUtils.getUserInfo().getId();

        return busScrapMapper.updateCheck(id ,userId);

    }
    public SysUserEntity getSysById(@Param("userId")Long userId){
        return busScrapMapper.getSysById(userId);
    }

    public int getBusScrapInfo(String equipmentCode) {
        BusScrapEntity busDepreciationEntity = busScrapMapper.getbusScrapInfo(equipmentCode);
        if(busDepreciationEntity!=null){
            return 1;
        }else
            return 0;
    }


//    public int getDepreciationInfo(String name){
//
//        BusDepreciationEntity b= busDepreciationMapper.getDepreciationInfo(name);
//        if(b!=null){
//            return 1;
//        }else
//            return 0;
//
//    }




}
